package com.example.text2.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.text2.R;
import com.example.text2.bean.Video;

import java.util.ArrayList;
import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;

/**
 * Created by 段傅华 on 2018/12/13.
 */

public class RlvAdapter2 extends RecyclerView.Adapter{
    private  Context mContext;
    private  ArrayList<Video.V9LG4B3A0Bean> mList;

    public RlvAdapter2(ArrayList<Video.V9LG4B3A0Bean> list, Context context) {
        this.mList=list;
        this.mContext=context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.item2layout, null, false);
        MyViewHolder myViewHolder = new MyViewHolder(inflate);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        MyViewHolder holder1= (MyViewHolder) holder;
        holder1.mTv.setText(mList.get(position).getTitle());
        holder1.mJCVideoPlayer.setUp(mList.get(position).getMp4_url(),mList.get(position).getTopicName());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public void addData(List<Video.V9LG4B3A0Bean> list) {
        mList.addAll(list);
        notifyDataSetChanged();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        final TextView mTv;
        final JCVideoPlayer mJCVideoPlayer;

        public MyViewHolder(View itemView) {
            super(itemView);
            mTv = itemView.findViewById(R.id.item2_tv);
            mJCVideoPlayer = (JCVideoPlayer) itemView.findViewById(R.id.videocontroller1);
        }
    }
}
